<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:set var="base" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>登录</title>
  <link href="${base}/assets/css/public.css" rel="stylesheet">
  <link href="${base}/assets/css/login.css" rel="stylesheet">
  <script src="${base}/assets/js/jquery.min.js"></script>
  <%-- <script src="${base}/assets/js/jquery.validate.min.js"></script> --%>
   <%-- <script src="${base}/assets/js/formcheck.js"></script> --%>
  
</head>
<body>
<div class="login">
  <div class="logo"><img src="${base}/assets/img/logo.png" alt=""></div>
  <div class="content">
    <h3>登录</h3>
    <div style="background: #fff ;border: none;padding :0px;text-align: center;">
             <span id = "errorInfo"  ></span>
    </div>
    <form class="login-f" action="" method="post">
      <div class="form-gp">
        <div class="title">账号：</div>
        <input id="Name" name="Name" type="text">
        <div class="clear"></div>
      </div>

      <div class="form-gp">
        <div class="title">密码：</div>
        <input id="Pwd" name="Pwd" type="password">
        <div class="clear"></div>
      </div>

      <div class="form-gp">
        <div class="title">验证码： </div>
        <input class="Code" type="text" autocomplete="off"
                  id="validCode"     placeholder="验证码" name="validCode" style="width:43%;float:left;"/>
                <div class="validImg">
                    <img onclick=fnChangePassCode(); id="validImg" width="80" height="43" src="${base}/validCode.do">
                </div>
        <!-- <input id="Code" name="Code" type="text">
        <div class="validImg"><img onclick="" id="validImg" width="80" height="40" src="images/code.jpg"></div> -->
        <div class="clear"></div>
      </div>

      <button type="button" onclick="loginclick()" class="login-btn form-button submit">登录</button>
    </form>
  </div>
  <p>2017 © 管理系统 | 神华科技.</p>
</div>
</body>
<script type="text/javascript">
	function fnChangePassCode(){
		document.getElementById("validImg").src="${base}/validCode.do?num=" + Math.random();
		//$("#validImg").attr('src',"${base}/validCode.do?num=" + Math.random());
	}
	function loginclick(){
		var name = $("#Name").val();
		var ps = $("#Pwd").val();
		var cd = $("#validCode").val();
		if(!name){
			alert("用户名不能为空！");
			return false;
		}
		if(!ps){
			alert("密码不能为空！");
			return false;
		}
		if(!cd){
			alert("验证码不能为空！");
			return false;
		}
		var oParameters = {
				"name" : name,
				"validCode" : cd,
				"password" : ps
		};
		$.ajax({
			url:'${base}/login.do',
			data : JSON.stringify(oParameters),
			type : 'POST',
			dataType:"json",
		    contentType: "application/json",
			success : function(oData) {
				var title = oData.title;
				if(title =="error"){
					fnChangePassCode();
					$("#errorInfo").html(oData.msg);
				}else {
					window.location.href = '/backstatistics/first.do';
				}							
			},
		});
	}
	</script>
</html>